package com.letukeji.web.riverdelictmanagement.controller.user;

import com.letukeji.web.riverdelictmanagement.bean.Admin;
import com.letukeji.web.riverdelictmanagement.bean.ApiResult;
import com.letukeji.web.riverdelictmanagement.bean.User;
import com.letukeji.web.riverdelictmanagement.service.AdminService;
import com.letukeji.web.riverdelictmanagement.service.BorrowingService;
import com.letukeji.web.riverdelictmanagement.service.CategoryService;
import com.letukeji.web.riverdelictmanagement.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (Admin)表控制层
 *
 * @author 陈华强
 * @since 2019-10-22 13:13:08
 */
@RestController
@RequestMapping("login")
public class LoginController {
    /**
     * 服务对象
     */
    @Resource
    private AdminService adminService;

    @Resource
    private CategoryService categoryService;

    @Resource
    private BorrowingService borrowingService;

    @Resource
    private UserService userService;

    @RequestMapping("check")
    public ApiResult doLogin(User user, HttpServletRequest request) {
        System.out.println("11111111111111111111111");
        System.out.println("2222222222222222222222");
        User u = userService.Login(user);
        if (u != null) {
            // 登陆成功后将用户对象存入session中
            request.getSession().setAttribute("user", u);
            return ApiResult.success("登录成功");
        } else {
            return ApiResult.fail("用户名或密码错误");
        }
    }

}